﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;

namespace Workflows.Components.TextMining.EnumerationObjects
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class TestTableDataExtractionOutput:ResultBase
    {
        #region  doc list props
        private int _TotalDocCount;
        /// <summary></summary>
        public int TotalDocCount
        {
            get
            {
                return this._TotalDocCount;
            }
            set
            {
                this._TotalDocCount = value;
            }
        }

        private int _DocMissed;
        /// <summary></summary>
        public int DocMissed
        {
            get
            {
                return this._DocMissed;
            }
            set
            {
                this._DocMissed = value;
            }
        }

        private int _DocExtra;
        /// <summary></summary>
        public int DocExtra
        {
            get
            {
                return this._DocExtra;
            }
            set
            {
                this._DocExtra = value;
            }
        }

        private int _DocDuplicated;
        /// <summary></summary>
        public int DocDuplicated
        {
            get
            {
                return this._DocDuplicated;
            }
            set
            {
                this._DocDuplicated = value;
            }
        }

        private string _DocListPerformanceResultFilePath;
        /// <summary></summary>
        public string DocListPerformanceResultFilePath
        {
            get
            {
                return this._DocListPerformanceResultFilePath;
            }
            set
            {
                this._DocListPerformanceResultFilePath = value;
            }
        }
        #endregion

        #region table scan props
        private int _DocsHavingTable;
        /// <summary></summary>
        public int DocsHavingTable
        {
            get
            {
                return this._DocsHavingTable;
            }
            set
            {
                this._DocsHavingTable = value;
            }
        }

        private int _TableDetectionMissed;
        /// <summary></summary>
        public int TableDetectionMissed
        {
            get
            {
                return this._TableDetectionMissed;
            }
            set
            {
                this._TableDetectionMissed = value;
            }
        }

        private int _TableDetectionFalsePositive;
        /// <summary></summary>
        public int TableDetectionFalsePositive
        {
            get
            {
                return this._TableDetectionFalsePositive;
            }
            set
            {
                this._TableDetectionFalsePositive = value;
            }
        }

        private string _TableScanPerformanceResultFilePath;
        /// <summary></summary>
        public string TableScanPerformanceResultFilePath
        {
            get
            {
                return this._TableScanPerformanceResultFilePath;
            }
            set
            {
                this._TableScanPerformanceResultFilePath = value;
            }
        }
        #endregion

        #region table layout
        private int _PagesWithTableLayout;
        /// <summary></summary>
        public int PagesWithTableLayout
        {
            get
            {
                return this._PagesWithTableLayout;
            }
            set
            {
                this._PagesWithTableLayout = value;
            }
        }

        private int _ScannedTableLayoutFailed;
        /// <summary></summary>
        public int ScannedTableLayoutFailed
        {
            get
            {
                return this._ScannedTableLayoutFailed;
            }
            set
            {
                this._ScannedTableLayoutFailed = value;
            }
        }

        private int _ElectronicTableLayoutFailed;
        /// <summary></summary>
        public int ElectronicTableLayoutFailed
        {
            get
            {
                return this._ElectronicTableLayoutFailed;
            }
            set
            {
                this._ElectronicTableLayoutFailed = value;
            }
        }

        private string _TableLayoutPerformanceResultFilePath;
        /// <summary></summary>
        public string TableLayoutPerformanceResultFilePath
        {
            get
            {
                return this._TableLayoutPerformanceResultFilePath;
            }
            set
            {
                this._TableLayoutPerformanceResultFilePath = value;
            }
        }
        #endregion

        #region table extract
        private int _TotalTables;
        /// <summary></summary>
        public int TotalTables
        {
            get
            {
                return this._TotalTables;
            }
            set
            {
                this._TotalTables = value;
            }
        }

        private int _DocsMissedExtraction;
        /// <summary></summary>
        public int DocsMissedExtraction
        {
            get
            {
                return this._DocsMissedExtraction;
            }
            set
            {
                this._DocsMissedExtraction = value;
            }
        }

        private int _DocsWithFewerRecords;
        /// <summary></summary>
        public int DocsWithFewerRecords
        {
            get
            {
                return this._DocsWithFewerRecords;
            }
            set
            {
                this._DocsWithFewerRecords = value;
            }
        }

        private string _TableExtractPerformanceResultFilePath;
        /// <summary></summary>
        public string TableExtractPerformanceResultFilePath
        {
            get
            {
                return this._TableExtractPerformanceResultFilePath;
            }
            set
            {
                this._TableExtractPerformanceResultFilePath = value;
            }
        }
        #endregion

        #region ctor
        /// <summary>
        /// 
        /// </summary>
        public TestTableDataExtractionOutput():base(Guid.Empty, Guid.Empty)
        {
            this._TotalDocCount = 0;
            this._DocMissed = 0;
            this._DocExtra = 0;
            this._DocDuplicated = 0;
            this._DocListPerformanceResultFilePath = string.Empty;

            this._DocsHavingTable = 0;
            this._TableDetectionMissed = 0;
            this._TableDetectionFalsePositive = 0;
            this._TableScanPerformanceResultFilePath = string.Empty;

            this._PagesWithTableLayout = 0;
            this._ScannedTableLayoutFailed = 0;
            this._ElectronicTableLayoutFailed = 0;
            this._TableLayoutPerformanceResultFilePath = string.Empty;

            this._TotalTables = 0;
            this._DocsMissedExtraction = 0;
            this._DocsWithFewerRecords = 0;
            this._TableExtractPerformanceResultFilePath = string.Empty;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="componentID"></param>
        /// <param name="jobTicketID"></param>
        /// <param name="docCount"></param>
        /// <param name="docMissed"></param>
        /// <param name="docExtra"></param>
        /// <param name="docDuplicated"></param>
        /// <param name="docListPerformanceFilePath"></param>
        /// <param name="docsHavingTable"></param>
        /// <param name="tableDetectMissed"></param>
        /// <param name="tableDetectExtra"></param>
        /// <param name="tableDetectPerformanceFilePath"></param>
        /// <param name="pagesWithTable"></param>
        /// <param name="scannedTableLayoutFailed"></param>
        /// <param name="electronicTableLayoutFailed"></param>
        /// <param name="tableLayoutPerformanceFilePath"></param>
        /// <param name="totalTables"></param>
        /// <param name="tableExtractMissed"></param>
        /// <param name="tableExtractWithLessRecords"></param>
        /// <param name="tableExtractPerformanceFilePath"></param>
        public TestTableDataExtractionOutput(Guid componentID, Guid jobTicketID,
            int docCount, 
            int docMissed,
            int docExtra, 
            int docDuplicated, 
            string docListPerformanceFilePath,
            int docsHavingTable,
            int tableDetectMissed,
            int tableDetectExtra,
            string tableDetectPerformanceFilePath,
            int pagesWithTable,
            int scannedTableLayoutFailed,
            int electronicTableLayoutFailed,
            string tableLayoutPerformanceFilePath, 
            int totalTables,
            int tableExtractMissed,
            int tableExtractWithLessRecords,
            string tableExtractPerformanceFilePath
            ) : base(componentID, jobTicketID)
        {
            this._TotalDocCount = docCount;
            this._DocMissed = docMissed;
            this._DocExtra=docExtra;
            this._DocDuplicated = docDuplicated;
            this._DocListPerformanceResultFilePath = docListPerformanceFilePath;
            this._DocsHavingTable = docsHavingTable;
            this._TableDetectionMissed = tableDetectMissed;
            this._TableDetectionFalsePositive = tableDetectExtra;
            this._TableScanPerformanceResultFilePath = tableDetectPerformanceFilePath;
            this._PagesWithTableLayout = pagesWithTable;
            this._ScannedTableLayoutFailed = scannedTableLayoutFailed;
            this._ElectronicTableLayoutFailed = electronicTableLayoutFailed;
            this._TableLayoutPerformanceResultFilePath = tableLayoutPerformanceFilePath;
            this._TotalTables = totalTables;
            this._DocsMissedExtraction=tableExtractMissed;
            this._DocsWithFewerRecords = tableExtractWithLessRecords;
            this._TableExtractPerformanceResultFilePath = tableExtractPerformanceFilePath;
        }
        #endregion 

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xNode"></param>
        /// <returns></returns>
        public override ResultBase Instantiate(XmlNode xNode)
        {
            if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
            {
                TestTableDataExtractionOutput output = new TestTableDataExtractionOutput();

                output.TotalDocCount = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "TotalDocCount", "0"));
                output.DocMissed = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "DocMissed", "0"));
                output.DocExtra = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "DocExtra", "0"));
                output.DocDuplicated = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "DocDuplicated", "0"));
                output.DocListPerformanceResultFilePath = XmlDataUtil.GetAttributeValue(xNode,
                                                                                        "DocListPerformanceResultFilePath",
                                                                                        "");

                output.DocsHavingTable = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "DocsHavingTable", "0"));
                output.TableDetectionMissed =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "TableDetectionMissed", "0"));
                output.TableDetectionFalsePositive =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "TableDetectionFalsePositive", "0"));
                output._TableScanPerformanceResultFilePath = XmlDataUtil.GetAttributeValue(xNode,
                                                                                           "TableDetectPerformanceResultFilePath",
                                                                                           "");

                output.PagesWithTableLayout =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "PagesWithTableLayout", "0"));
                output.ScannedTableLayoutFailed =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "ScannedTableLayoutFailed", "0"));
                output.ElectronicTableLayoutFailed =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "ElectronicTableLayoutFailed", "0"));
                output.TableLayoutPerformanceResultFilePath = XmlDataUtil.GetAttributeValue(xNode,
                                                                                            "TableLayoutPerformanceResultFilePath",
                                                                                            "");

                output.TotalTables = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "TotalTables", "0"));
                output.DocsMissedExtraction =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "DocsMissedExtraction", "0"));
                output.DocsWithFewerRecords =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "DocsWithFiewerRecords", "0"));
                output.TableExtractPerformanceResultFilePath = XmlDataUtil.GetAttributeValue(xNode,
                                                                                             "TableExtractPerformanceResultFilePath",
                                                                                             "");

                return output;
            }
            else
            {
                throw new Exception("Unable to instantiate output: invalid type specified in xml node");
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TotalDocCount", this.TotalDocCount.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocMissed", this.DocMissed.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocExtra", this.DocExtra.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocDuplicated", this.DocDuplicated.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocListPerformanceResultFilePath", this.DocListPerformanceResultFilePath);

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocsHavingTable", this.DocsHavingTable.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TableDetectionMissed", this.TableDetectionMissed.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TableDetectionFalsePositive",
                                        this.TableDetectionFalsePositive.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TableDetectionPerformanceResultFilePath",
                                        this.TableScanPerformanceResultFilePath);

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "PagesWithTableLayout", this.PagesWithTableLayout.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "ScannedTableLayoutFailed",
                                        this.ScannedTableLayoutFailed.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "ElectronicTableLayoutFailed",
                                        this.ElectronicTableLayoutFailed.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TableLayoutPerformanceResultFilePath",
                                        this.TableLayoutPerformanceResultFilePath);

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TotalTables", this.TotalTables.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocsMissedExtraction", this.DocsMissedExtraction.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "DocsWithFewerRecords", this.DocsWithFewerRecords.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "TableExtractionPerformanceResultFilePath",
                                        this.TableExtractPerformanceResultFilePath);

            return xNode;
        }
    }
}
